import argparse
import pandas as pd

from common import gen_summary, update_chan_same_names

from sales_detail_process import sales_detail_process
from sales_profit import sales_profit
from channel_profit import channel_profit


def get_opts():
    parser = argparse.ArgumentParser()

    parser.add_argument('--data-path', type=str, required=True,
                        help='path to excel')
    parser.add_argument('--summary-path', type=str, 
                        default='summary.txt', 
                        help='path to summary')
    parser.add_argument('--merge-path', type=str, required=True, 
                        help='path to merge xls')
    parser.add_argument('--sheet-src-name', type=str,
                        default='订单明细',
                        help='sheet source name')
    parser.add_argument('--sale-profit-name', type=str,
                        default='商品利润率',
                        help='sheet profit sheet name')
    parser.add_argument('--chan-profit-name', type=str,
                        default='渠道利润率',
                        help='channel profit source name')
    return parser.parse_args()




if __name__ == '__main__':

    hparams = get_opts()

    wb_path = hparams.data_path
    mg_path = hparams.merge_path
    sheet_src_name = hparams.sheet_src_name
    sale_profit_name = hparams.sale_profit_name
    chan_profit_name = hparams.chan_profit_name
    summary_path = hparams.summary_path
    
    update_chan_same_names(mg_path)
    # 
    sales_detail_process(wb_path, sheet_src_name)
    
    sales_profit(wb_path, sheet_src_name, sale_profit_name)
    
    channel_profit(wb_path, sheet_src_name, chan_profit_name)
    
    gen_summary(summary_path, wb_path)
